<template>
	<view class="wdthdrawal">
		<view class="pagetitle">
			<uni-breadcrumb separator="/">
				<uni-breadcrumb-item v-for="(route,index) in routes" :key="index" :to="route.to">
					{{route.name}}
				</uni-breadcrumb-item>
			</uni-breadcrumb>
			<view class="right">
				<view class="select">
					<uni-data-select
					   v-model="selectTimeVal"
					   :localdata="range"
						@change="changeDateSelect"
					></uni-data-select>
				</view>
			</view>	
		</view>
		<loading v-if="loading"></loading>
		
		<view class="comment">
			<view class="comment-item"  v-for="(item,index) in commentData" >
				<view class="item-user">
					<view class="item-user-head">
						<image v-if="item.user.avatar" @click="eventImage(item.user.avatar)"
							:src="item.user.avatar+'?x-oss-process=image/resize,m_fixed,h_100,w_100'" mode="widthFix" style="width:80rpx;border-radius:50%" 
						></image>
							<text class="text titleApp " >
								{{item.user.nickname}}
							</text>
							<text class="text" style="font-size:12px; color:#ccc">
								{{item.is_update?'已修改':''}}
							</text>
							<view style="flex:1;text-align: right;color:#555" >
								<uni-dateformat format="yyyy年MM月dd日 hh:mm" :date="item.create_date"></uni-dateformat>
							</view>
					</view>
					
				</view>
				<view class="item-body">
					<view class="body_row">
						<view class="body_row_head">
							<view class=" ">
								<image v-if="item.shop.logo" @click="eventImage(item.shop.logo)"
								 :src="item.shop.logo+'?x-oss-process=image/resize,m_fixed,h_100,w_100'" mode="widthFix" style="width:80rpx;border-radius:50% " ></image>
							</view>
							<view class=" titleApp"  style="font-weight:bold" >
								{{item.shop.title}}
								<view class=""   >
									<uni-rate size="18" readonly activeColor="#ff8800" :value="item.shop.average_score?item.shop.average_score:5" />
								</view>
							</view>
							<view class="" :style="`color:${shopriderIF(0,item.shop.total_score).color };font-weight:bold`">
								{{shopriderIF(0,item.shop.total_score).text }}
							</view>
						</view>
						<view class="body_row_body" >
							<view class="body_row_body_xing">
								<view class=""  >
									&nbsp; 包装
								</view>
								<view class="">
									<uni-rate size="18" readonly activeColor="#ff9900" :value="item.shop.shop_package?item.shop.shop_package:5" />
								</view>
								<view class=""  >
									&nbsp; 服务
								</view>
								<view class="">
									<uni-rate size="18" readonly activeColor="#ff9900" :value="item.shop.shop_attitude?item.shop.shop_attitude:5" />
								</view>
								<view class=""  >
									&nbsp; 菜品
								</view>
								<view class="">
									<uni-rate size="18" readonly activeColor="#ff9900" :value="item.shop.shop_taste?item.shop.shop_taste:5" />
								</view>
							</view>
							<uni-collapse style="background:#f9f9f9;margin:10px ;" >
								<uni-collapse-item style="background:#f9f9f9;" :title="item.shop.shop_content?item.shop.shop_content:'暂无'" :show-animation="true">
									<view class="" style="background:#f9f9f9;">
										<text class="text">
											{{item.shop.shop_content?item.shop.shop_content:'暂无'}}
										</text>
									</view>
								</uni-collapse-item>
							</uni-collapse>
						</view>
					</view>
					<view class="body_row">
						<view class="body_row_head">
							<view class="">
								<image v-if="item.rider.avatar" @click="eventImage(item.rider.avatar)"
									:src="item.rider.avatar+'?x-oss-process=image/resize,m_fixed,h_100,w_100'" mode="widthFix" style="width:80rpx;border-radius:50%"
								></image>
							</view>
							<view >
								<text class="titleApp">
									{{item.rider.name}}
								</text>
								<view class="">
									<uni-rate size="18" readonly activeColor="#ff8800" :value="item.rider.average_score?item.rider.average_score:5" />
								</view>
							</view>
							<view class="" :style="`color:${shopriderIF(1,item.rider.total_score).color };font-weight:bold`">
								{{shopriderIF(1,item.rider.total_score).text }}
							</view>
						</view>
						<view class="body_row_body_xing" >
								<view class="left"  >
									&nbsp; 速度
								</view>
								<view class="left">
									<uni-rate size="18" readonly activeColor="#ff9900" :value="item.rider.rider_speed?item.rider.rider_speed:5" />
								</view>
								<view class="left"   >
									形象
								</view>
								<view class="left">
									<uni-rate size="18" readonly activeColor="#ff9900" :value="item.rider.rider_wear?item.rider.rider_wear:5" />
								</view>
								<view class="left"  >
									&nbsp; 态度
								</view>
								<view class="left">
									<uni-rate size="18" readonly activeColor="#ff9900" :value="item.rider.rider_attitude?item.rider.rider_attitude:5" />
								</view>
						</view>
						<uni-collapse style="background:#f9f9f9;margin:10px ;" >
							<uni-collapse-item style="background:#f9f9f9;" :title="item.rider.rider_content?item.rider.rider_content:'暂无'" :show-animation="true">
								<view class="" style="background:#f9f9f9;">
									<text class="labelApp">
										{{item.rider.rider_content?item.rider.rider_content:'暂无'}}
									</text>
								</view>
							</uni-collapse-item>
						</uni-collapse>
						<view class="row_scroll" id="outsideDiv" v-if="item.rider">
							<text class="image labelApp" v-for="(item,index) in item.rider.label" style="font-size:13px" >
								{{item}}
							</text>
						</view>
					</view>
				</view>
				<view class="row_scroll" id="outsideDiv" v-if="item.images.length !== 0">
					<view class="image" v-for="(img,k) in item.images" :key="k">
						<image @click="eventImage(img)" :src="img+'?x-oss-process=image/resize,m_fixed,h_100,w_100'" mode="widthFix" style="width:100px;border:1px solid #ccc"></image>
					</view>
				</view>
				
				
				<view class="body_button">
					<view class="button" >
						<button size="mini" type=" " @click="goUrl(`/pages/order/uni-pay-orders/detail?id=${item.order.order_no}`)" >
							查订单
						</button>
						<button size="mini" type=" " @click="goUrl(`/pages/shop/shop/shop-info?_uid=${item.shop._id}`)" >
							商家
						</button>
						<button size="mini" type=" " @click="goUrl(`/pages/rider/rider_users/detail?_uid=${item.rider._id}`)" >
							骑手
						</button>
						<button size="mini" type=" " @click="goUrl(`/pages/system/user/detail?id=${item.user._id}`)" >
							用户
						</button>
					</view>
				</view>
				
				
				
			</view>
		</view>
				
		<view class="uni-pagination-box">
			<uni-pagination @change="enventFneye" :v-model="currentPage" :pageSize="limit" title="" :total="total"></uni-pagination>
		</view>
		
	</view>
</template>

<script>
	import {enumScore} from "./list.js"
	import Util from "@/js_sdk/validator/util.js"
	import { areaPower } from "@/js_sdk/manage-area/manage.js";
	const global = uniCloud.importObject("global",{customUI:true})
	const db = uniCloud.database()
	let dayDate ;
	export default {
		data() {
			return {
				loading:true,
				routes: [
					{to: "/pages/index/index",name: "首页",},
					{to: "",name: "日志管理" },
					{to: "",name: "用户评论" }
				],
				// 分页
				total:0, //  总条数
				skip:0,// 开始查询位置
				limit:12, // 单词查询条数
				currentPage:1, // 当前页
				//a 日期下拉框
				selectTimeVal:4,
				range:[
					{value: 0,text: "全部"},
					{value: 1,text: "骑手好评"},
					{value: 3,text: "骑手中评"},
					{value: 4,text: "骑手差评"},
					{value: 5,text: "商家好评"},
					{value: 6,text: "商家中评"},
					{value: 7,text: "商家差评"},
				],
				_uid:null,
				data:[],
				commentData:[],
				where:{
					"shop._id.area_all.value":db.command.in( areaPower() ),
					$or:[
						{ "rider.total_score": db.command.lt(6)  }
					]
				},
			}
		},
		onLoad(e) {
			if (e._uid) {
				this._uid = e._uid
				this.where.$or = [
					{"rider._id":this._uid},
					{"shop._id":this._uid}
				]
			}
			this.getData()
		},
		methods: {
			getData(){
				this.loading = true
				let commentField =  "_id,shop._id as shop_id,shop,user,rider,order,images,is_update,like_number,create_date,create_ip"
				const comment = db.collection("comment").field(commentField).getTemp({
					getOne: false
				})
				const shops = db.collection("shop").field("area_all,_id").getTemp()
				db.collection(comment,shops)
					.where(this.where)
					.orderBy("create_date desc")
					.skip(this.skip).limit(this.limit).get({getOne:false,getCount:true,customUI:true})
				.then(res=>{
					this.commentData = res.result.data
					this.total = res.result.count
					this.loading = false
				})
			},
			// 分页
			enventFneye(val){
				this.loading = true
				this.skip = (val.current-1)*12
				this.getData()
			},
			// 下拉框
			changeDateSelect(e){
				const dbCmd = db.command
				let tempArr  = []
				if(this._uid ) {
					tempArr = [
						enumScore(e),
						...this.where.$or
					]
				}else {
					tempArr = [
						enumScore(e),
					]
				}
				this.where.$or = tempArr
				this.getData()
			},
			/**
			 * 商家/骑手评分审判
			 * @param platform 0商家 、1骑手
			 * @param number 分数*/
			 shopriderIF(platform,number){
				 if (platform===0) {
					if (number <= 18 && number >= 13 )
						return {color:"#74b9ff",text:"良好"}
					else if (number <= 13 && number >= 8)
						return {color:"#ffbe76",text:"一般"}
					else if (number <= 8)
						return {color:"#ff7979",text:"差劲"}
					else
						return {color:"#78e08f",text:"优秀"}
				 }
				 else if (platform === 1) {
					 if (number <= 13 && number >= 10 )
					 	return {color:"#74b9ff",text:"良好"}
					 else if (number <= 10 && number >= 6)
						return {color:"#ffbe76",text:"一般"}
					 else if (number <= 6)
						return {color:"#ff7979",text:"差劲"}
					 else
					 	return {color:"#78e08f",text:"优秀"}
				 }
			 },
			/**
			 * 获取指定日期的开始和结束时间戳
			 * @returns {Object} - 返回包含开始时间戳和结束时间戳的对象
			 */
			getStartAndEndTimestamp() {
				const date = new Date(); 
				const sevenDaysAgo = new Date(new Date().getTime() - 7 * 24 * 60 * 60 * 1000);
				const startTime = sevenDaysAgo.setHours(0, 0, 0, 0); // 将指定日期设置为零点，返回开始时间戳
				const endTime = date.setHours(23, 59, 59, 999); // 将指定日期设置为当天的结束，返回结束时间戳
				return { startTime: startTime, endTime: endTime };
			},
			navigateTo(url, clear) {
				// clear 表示刷新列表时是否清除页码，true 表示刷新并回到列表第 1 页，默认为 true
				uni.navigateTo({
					url,
					events: {
						refreshData: () => {
							this.loadData(clear)
						}
					}
				})
			},
			initText(text){
				return Util.shortenString(text?text:'',10)
			},
			initMobile(mobile){
				return Util.formatPhoneNumber(mobile)
			},
			shortenString(content) {
				return Util.shortenString(content)
			},
			// 放大图片
			eventImage(image) {
				uni.previewImage({
					urls: [image]
				})
			},
			goUrl(Url) {
				uni.navigateTo({
					url: Url
				})
			},
			initMobile(mobile) {
				return Util.formatPhoneNumber(mobile)
			},
			goback() {
				uni.navigateBack(1)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.animated-item {
		opacity: 0;
		transform: translate(0,-30px) ;
		animation: fadeInLeft .5s ease forwards;
	}
	@keyframes fadeInLeft {
		to {
			opacity: 1;
			transform: translate(0);
		}
	}
	
	.select{
		width:500rpx;
		margin:0 20rpx;
	}
	.warn{
		padding:10rpx;
	}
	.swiper-box{
		width:200px;
		height:60px;
	}
	.title{
		font-size:16px;font-weight: bold;
	}
	.table{
		margin:50rpx 20rpx;
		border:1px solid #eee;
		border-bottom:none
	}
	.wdthdrawal{
		padding:20rpx;
		font-size:14px;
	}
	@import url('./comment.scss');
</style>
